#{extends 'CRUD/layout.html' /}
#{set title:messages.get('crud.list.title', type.name) /}
<div id="crudList" class="${type.name}">

    <h2 id="crudListTitle">&{'crud.list.title', type.name}</h2>

    <div id="crudListSearch">
    #{crud.search /}
    </div>

    <div id="crudListTable">
    #{crud.table fields:['name', 'surname', 'email', 'Activo','Tareas','Documentos', 'Inscripciones'] }
        #{crud.custom 'Activo'}
            <input id="${object.id}check" type="checkbox"
                   onclick="changePersonStatus(${object.id})" ${object.isActive ==true  ? 'checked':'' } >
        #{/crud.custom}
        #{crud.custom 'Tareas'}
            <a href="@{People.show(object.id)}">
                Ver/Editar
            </a>
        #{/crud.custom}
        #{crud.custom 'Documentos'}
            <a href="@{PeopleDocuments.listForPerson(object.id)}">
                Ver
            </a>
        #{/crud.custom}
        #{crud.custom 'Inscripciones'}
            <a href="@{Inscriptions.listForPerson(object.id)}">
                Ver
            </a>
        #{/crud.custom}
    #{/crud.table}
    </div>

    <div id="crudListPagination">
    #{crud.pagination /}
    </div>

    <p id="crudListAdd">
        <a href="@{blank()}">&{'crud.add', type.modelName}</a>
    </p>
</div>

<script>
    function changePersonStatus(id) {
        //put token request
        var checked = $('#' + id + 'check').is(':checked');
        var url = "@{changePersonStatus}";

        $.post(url, { "id":id, "checked":checked},
                function (data) {
                    showStatus(true, data.message);
                }, "json")
                .error(function () {
                    showStatus(false, "505");
                });
    }

</script>

